﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using XKJ.OAWeb.Api.Filters;
using XKJ.OAWeb.Application;
using XKJ.OAWeb.Models;

namespace XKJ.OAWeb.Api.Controllers
{
    /// <summary>
    /// 角色模块
    /// </summary>
    [Route("api/[controller]/[action]")]
    //授权特性，表示：下面的所有方法都必须登录才能调用
    [Authorize]
    public class RoleController : ControllerBase
    {
        IRoleService _autofacService;

        public RoleController(IRoleService autofacService)
        {
            _autofacService = autofacService;
        }
        /// <summary>
        /// 显示
        /// </summary>
        /// <param name="Pageindex"></param>
        /// <param name="Pagesize"></param>
        /// <param name="RoleName"></param>
        /// <returns></returns>
        [HttpGet]
        //允许匿名访问的特性
        [AllowAnonymous]
        public IActionResult RoleShow(int Pageindex, int Pagesize,string? RoleName)
        {
            return Ok(_autofacService.RoleShow(Pageindex, Pagesize, RoleName));
        }
        /// <summary>
        /// 根据Id删除
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpGet]
        //允许匿名访问的特性
        [AllowAnonymous]
        public IActionResult RoleDeleteId(int Id)
        {
            return Ok(_autofacService.RoleDeleteId(Id));
        }
        /// <summary>
        /// 根据Id反填数据
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpGet]
        //允许匿名访问的特性
        [AllowAnonymous]
        public IActionResult RoleBackfill(int Id)
        {
            return Ok(_autofacService.RoleBackfill(Id));
        }
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="role"></param>
        /// <returns></returns>
        [HttpPost]
        //允许匿名访问的特性
        [AllowAnonymous]
        public IActionResult RoleUptdate(Role role)
        {
            return Ok(_autofacService.RoleUptdate(role));
        }
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="role"></param>
        /// <returns></returns>
        [HttpPost]
        //允许匿名访问的特性
        [AllowAnonymous]
        public IActionResult RoleAdd(Role role)
        {
            return Ok(_autofacService.RoleAdd(role));
        }
        /// <summary>
        /// 角色权限显示
        /// </summary>
        /// <param name="Pageindex"></param>
        /// <param name="Pagesize"></param>
        /// <param name="RoleName"></param>
        /// <returns></returns>
        [HttpGet]
        //允许匿名访问的特性
        [AllowAnonymous]
        public IActionResult RoleLimitsShow(int Pageindex, int Pagesize, string? RoleName)
        {
            return Ok(_autofacService.RoleLimitsShow(Pageindex, Pagesize, RoleName));
        }
    }
}
